//
//  YMMainBarController.swift
//  YMWeiBo
//
//  Created by mimi on 16/7/19.
//  Copyright © 2016年 mimi. All rights reserved.
//

import UIKit

class YMMainBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
//        composeView
      let composeView:YMComposeView = {
           let view = YMComposeView()
            view.backgroundColor = UIColor.brownColor()
            return view
        }()
        
        
        let tabBar = YMTabBar()
//        tabBar.ymDelegate = self

        setValue(tabBar, forKey: "tabBar")
    
        tabBar.editClosure = {
            self.view.addSubview(composeView)
            composeView.composeViewShow(self)
            
            print("撰写")

            
//            self.presentViewController(UINavigationController(rootViewController: YMComposeViewController()), animated: true, completion: nil)
        }
        

    
    addChildViewController("首页", imageName: "tabbar_home", vc: YMHomeViewController())
    addChildViewController("消息", imageName: "tabbar_message_center", vc: YMMessageViewController())
    addChildViewController("发现", imageName: "tabbar_discover", vc: YMDiscoverViewController())
    addChildViewController("我", imageName: "tabbar_profile", vc: YMProfileViewController())
        
        
    }
    //        添加控制器
    func addChildViewController(title:String ,imageName:String ,vc:UIViewController) {

        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageName)?.imageWithRenderingMode(.AlwaysOriginal)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageName)_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: .Selected)
        
        addChildViewController(UINavigationController(rootViewController: vc))
    }


}

